package com.kaiyidiannao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.kaiyidiannao.main.R;
import com.kaiyidiannao.model.bean.TourBean;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by david on 14-4-22.
 * 凑队去
 */
public class TourLineAdapter extends ImageLoaderBaseAdapter {
    private LayoutInflater layoutInflater;
    private List<?> list = new ArrayList<TourBean>();

    public TourLineAdapter(Context context, List<?> list) {
        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(context));
        this.list = list;
        this.layoutInflater =LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = null;
        TextView nameTextView = null;
        TextView  introduceTextView = null;
        TextView hitsTextview = null;
        TourBean bean = null;

        try {
            bean = (TourBean) list.get(position);
            if (convertView==null) {
                convertView=layoutInflater.inflate(R.layout.tour_line_item_,null);
            }
            imageView = (ImageView) convertView.findViewById(R.id.tour_line_imageview);
            nameTextView = (TextView) convertView.findViewById(R.id.tour_line_name);
            introduceTextView = (TextView) convertView.findViewById(R.id.tour_line_introduce);
            hitsTextview = (TextView) convertView.findViewById(R.id.tour_line_hits);


            imageLoader.displayImage(bean.getThumb(),imageView, options, null);
            nameTextView.setText(bean.getTitle());
            introduceTextView.setText(bean.getIntroduce());
            hitsTextview.setText(bean.getHits());
        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }
}
